package com.example.demo.controller;

import com.example.demo.model.LeaveBill;
import com.example.demo.service.LeaveBillService;
import com.example.demo.utils.ActivitiUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.UUID;

@Controller
@RequestMapping("leave")
public class LeaveBillController {


    @Autowired
    LeaveBillService leaveBillService;

    @Autowired
    ActivitiUtils activitiUtils;


    @RequestMapping("create")
    @ResponseBody
    public void createProcessIns() {
        activitiUtils.createProcessIns();
    }

    @RequestMapping("/start")
    @ResponseBody
    public void insert(){
        String bussinessId = UUID.randomUUID().toString();
        String userId = "1";
        String reason ="病假";
        String day ="8";

        //业务代码
        LeaveBill leaveBill = new LeaveBill();
        leaveBill.setId(bussinessId);
        leaveBill.setUserId(userId);
        leaveBill.setReason(reason);
        leaveBill.setDay(day);
        leaveBillService.insert(leaveBill);

        activitiUtils.startProcess(bussinessId,userId,reason,day);

        activitiUtils.setOwner(bussinessId,userId);

    }

    @RequestMapping("/delete")
    @ResponseBody
    public void deleteProcess(){
        String deploymentId ="";
        activitiUtils.deleteProcess(deploymentId);
    }

    @RequestMapping("/active")
    @ResponseBody
    public void active(){
        String processDefinitionKey ="leaveProcess";
        activitiUtils.activate(processDefinitionKey);
    }


    @RequestMapping("/suspend")
    @ResponseBody
    public void suspend(){
        String processDefinitionKey ="leaveProcess";
        activitiUtils.suspend(processDefinitionKey);
    }




}
